package com.example.mychat.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.mychat.entity.Comment;
import com.example.mychat.mapper.CommentMapper;
import com.example.mychat.service.ICommentService;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class CommentServiceImpl implements ICommentService {
    @Resource
    CommentMapper commentMapper;

    @Override
    @Cacheable(value = "comment", key = "#messageId")
    public List<Comment> findCommentByMessageId(Long messageId) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("messageId", messageId);
        queryWrapper.orderByAsc("commentTime");
        return commentMapper.selectList(queryWrapper);
    }
}
